package cn.shyouchi.wuguanjia.android.ui.statistic.page;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.api.attendance.AttendanceApi;
import cn.shyouchi.wuguanjia.android.base.BaseFragment;
import cn.shyouchi.wuguanjia.android.widget.CircularProgressBar;

/**
 * A simple {@link Fragment} subclass.
 */
public class YearStatisticFragment extends BaseFragment {


    @BindView(R.id.rv_year_statistic)
    RecyclerView mRvYearStatistic;
    List<String> mEntities = new ArrayList<>();

    YearStatisticAdapter mAdapter;

    AttendanceApi mAttendanceApi;

    String projectId = "";
    @BindView(R.id.tv_year)
    TextView mTvYear;
    @BindView(R.id.pro_rate)
    CircularProgressBar mProRate;
    @BindView(R.id.tv_newly_num)
    TextView mTvNewlyNum;
    @BindView(R.id.tv_leave_num)
    TextView mTvLeaveNum;
    @BindView(R.id.tv_rate)
    TextView mTvRate;

    YearStatisticEntity currentEntity;

    public YearStatisticFragment() {

    }


    @Override
    public void initInjector() {
        mAttendanceApi = new AttendanceApi(getContext());
        projectId = ((StatisticPageActivity) getActivity()).getProjectId();
    }

    @Override
    public int initContentView() {
        return R.layout.fragment_year_statistic;
    }

    @Override
    public void getBundle(Bundle bundle) {

    }

    @Override
    public void initUI(View view) {
        ButterKnife.bind(this, view);



        EventBus.getDefault().register(this);


        mAdapter = new YearStatisticAdapter(mEntities, projectId);
        mRvYearStatistic.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvYearStatistic.setAdapter(mAdapter);
        showContent(true);




    }

    @Override
    public void initData() {

    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onYearStatisticItemClick(YearStatisticEntity.ResultMessageBean entity) {
        showContent(true);
        mEntities.clear();
        mEntities.addAll(entity.getYear());
        mAdapter.notifyDataSetChanged();
    }


    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }



}
